package tv.acgn.advertisement.search.index.impl;

import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tv.acgn.advertisement.search.exception.AbstractAdSearchException;
import tv.acgn.advertisement.search.index.IndexAware;
import tv.acgn.advertisement.search.indexobejct.UnitDistrictIO;

/**
 * @author : junG
 * @program : advertisement-ad-search-index
 * @description :  推广单元-地区索引操作实现类
 * @date : 2019-07-14 20:12
 **/

@Service
@Slf4j
public class DistrictIndexImpl implements IndexAware<String, Set<UnitDistrictIO>> {

    private static Map<String, Set<UnitDistrictIO>> unitIdToDistrictMap = new ConcurrentHashMap<>();

    private static Map<String, Set<String>> districtToUnitMap = new ConcurrentHashMap<>();

    /**
     * <h2>通过索引的键获取值</h2>
     *
     * @param s [1] 键
     *
     * @return {@link Value} 值对象
     *
     * @throws AbstractAdSearchException 异常
     * @author junG
     * @description 通过索引的键获取值
     * @date 22:31 2019/6/30
     */
    @Override
    public Set<UnitDistrictIO> get(String unitId) throws AbstractAdSearchException {
        return Optional.ofNullable(unitIdToDistrictMap.get(unitId))
            .orElseGet(Collections::emptySet);
    }

    /**
     * <h2>新增一条索引</h2>
     *
     * @param unitId               [1] 键
     * @param unitDistrictIOS [2] 值对象
     *
     * @return {@link Void}
     *
     * @throws AbstractAdSearchException 异常
     * @author junG
     * @description 新增一条索引
     * @date 22:32 2019/6/30
     */
    @Override
    @SuppressWarnings({"Duplicates"})
    public void add(String unitId, Set<UnitDistrictIO> unitDistrictIOS) throws AbstractAdSearchException {
    }

    /**
     * <h2>更新索引键对应的索引值对象</h2>
     *
     * @param s               [1]
     * @param unitDistrictIOS [2]
     *
     * @return {@link Void}
     *
     * @throws AbstractAdSearchException 异常
     * @author junG
     * @description 更新索引键对应的索引值对象
     * @date 22:35 2019/6/30
     */
    @Override
    public void update(String s, Set<UnitDistrictIO> unitDistrictIOS) throws AbstractAdSearchException {

    }

    /**
     * <h2>删除索引对象</h2>
     *
     * @param s [1]
     *
     * @return {@link Void}
     *
     * @throws AbstractAdSearchException 异常
     * @author junG
     * @description 删除索引对象
     * @date 22:26 2019/6/30
     */
    @Override
    public void delete(String s) throws AbstractAdSearchException {

    }
}
